# ---------- 简介 ---------- #
# Bitmap.py
# 赵宗义, xinshengzzy@foxmail.com, 2021.2.12
# ---------- #
from math import ceil


class Bitmap:
    def __init__(self, size):
        self.size = ceil(size/8.0)
        self.哈希表 = bytearray(self.size)

    def set(self, index):
        k1 = int(index/8)
        k2 = index % 8
        self.哈希表[k1] = self.哈希表[k1] | (0x80 >> k2)

    def test(self, index):
        k1 = int(index/8)
        k2 = index % 8
        tmp = self.哈希表[k1] & (0x80 >> k2)
        if 0 == tmp:
            return False
        else:
            return True

    def reset(self):
        for i in range(self.size):
            self.哈希表[i] = 0x00
